using System;
using UnityEngine;

namespace UnityX
{
    [Serializable]
    public class MoveAnimationData
    {
        public bool enable = false;
        public Vector2 moveValue = Vector2.one;
        public MoveValueType valueType = MoveValueType.基于父亲滑出大小;
        [Range(0, 1)]
        public float curve = 0.5f;
        public Vector2 GetMovePosition(RectTransform rectTransform)
        {
            switch (valueType)
            {
                case MoveValueType.固定位置:
                    return moveValue;
                case MoveValueType.固定偏移:
                    return rectTransform.anchoredPosition + moveValue;
                case MoveValueType.基于自己大小偏移:
                    return rectTransform.anchoredPosition + rectTransform.rect.size * moveValue;
                case MoveValueType.基于父亲大小偏移:
                    {
                        RectTransform parentRectTransform = rectTransform.parent as RectTransform;
                        if (parentRectTransform != null)
                            return rectTransform.anchoredPosition + parentRectTransform.rect.size * moveValue;
                        else
                            return rectTransform.anchoredPosition + new Vector2(Screen.width, Screen.height) * moveValue;
                    }
                case MoveValueType.基于父亲滑出大小:
                    {
                        Rect rect = rectTransform.ExGetLocalRect();
                        RectTransform parentRectTransform = rectTransform.parent as RectTransform;
                        if (parentRectTransform != null)
                        {
                            return rectTransform.anchoredPosition + new Vector2(
                                moveValue.x < 0 ? rect.xMax : parentRectTransform.rect.width - rect.xMin,
                                moveValue.y < 0 ? rect.yMax : parentRectTransform.rect.height - rect.yMin) * moveValue;
                        }
                        else
                        {
                            return rectTransform.anchoredPosition + new Vector2(
                                moveValue.x < 0 ? rect.xMax : Screen.width - rect.xMin,
                                moveValue.y < 0 ? rect.yMax : Screen.height - rect.yMin) * moveValue;
                        }
                    }
                case MoveValueType.基于屏幕滑出大小:
                    {
                        Rect rect = rectTransform.ExGetWorldRect();
                        return rectTransform.anchoredPosition + new Vector2(
                            moveValue.x < 0 ? rect.xMax : Screen.width - rect.xMin,
                            moveValue.y < 0 ? rect.yMax : Screen.height - rect.yMin) * moveValue;
                    }
            }
            return moveValue;
        }
    }
}